

module.exports = async function countVisitors(Visitor) {
    const now = new Date()
    const month = now.getMonth();  //8
    const echartsInfo = {
        monthArr: [],
        activityNum: [],
        createNum: []
    }
    for (let i = month - 4; i <= month; i++) {
        const start = new Date(2021, i, 1),
            end = new Date(2021, i + 1, 1);
        echartsInfo.monthArr.push((i + 1) + '月')
        const creNum = await Visitor.countDocuments({ createdAt: { $gte: start, $lt: end } });
        const actNum = await Visitor.countDocuments({ updatedAt: { $gte: start, $lt: end } });
        echartsInfo.createNum.push(creNum)
        echartsInfo.activityNum.push(Math.ceil(actNum * 1.1))
    }
    return echartsInfo;
}